package gopi.labs.cloudspace;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swt.graphics.Rectangle;

public class CloudSpace implements SelectionListener {

	Display display;

	Shell shell;

	Menu menuBar, cloudSpaceMenu, helpMenu;

	MenuItem cloudSpaceHeader, helpMenuHeader , exitMenuHeader;

	MenuItem createCloudSpaceItem, dropCloudSpaceItem, modifyCloudSpaceItem, helpGetHelpItem;

	Label label;

	public CloudSpace() {
		createMenu();

	}

	private void createMenu() {
		display = new Display();
		shell = new Shell(display);
		shell.setText("Cloud Space");
		shell.setSize(1200, 800);

		

		menuBar = new Menu(shell, SWT.BAR);
		cloudSpaceHeader = new MenuItem(menuBar, SWT.CASCADE);
		cloudSpaceHeader.setText("&Cloud Space");
		cloudSpaceHeader.setAccelerator(SWT.MOD1 + 'C');
		
		cloudSpaceMenu = new Menu(shell, SWT.DROP_DOWN);
		cloudSpaceHeader.setMenu(cloudSpaceMenu);

		createCloudSpaceItem = new MenuItem(cloudSpaceMenu, SWT.NONE);
		createCloudSpaceItem.setText("&Create");
		createCloudSpaceItem.addSelectionListener(this);
		
		modifyCloudSpaceItem = new MenuItem(cloudSpaceMenu, SWT.NONE);
		modifyCloudSpaceItem.setText("&Modify");
		modifyCloudSpaceItem.addSelectionListener(this);
		
		dropCloudSpaceItem = new MenuItem(cloudSpaceMenu, SWT.NONE);
		dropCloudSpaceItem.setText("&Drop");
		dropCloudSpaceItem.addSelectionListener(this);

		helpMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
		helpMenuHeader.setText("&Help");
		helpMenuHeader.setAccelerator(SWT.MOD1 + 'H');
		
		helpMenu = new Menu(shell, SWT.DROP_DOWN);
		helpMenuHeader.setMenu(helpMenu);

		helpGetHelpItem = new MenuItem(helpMenu, SWT.PUSH);
		helpGetHelpItem.setText("&Get Help");
		helpGetHelpItem.addSelectionListener(this);

		exitMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
		exitMenuHeader.setText("&Exit");
		exitMenuHeader.setAccelerator(SWT.MOD1 + 'E');
		exitMenuHeader.addSelectionListener(this);
		exitMenuHeader.setData("ITEM", exitMenuHeader);
		
		shell.setMenuBar(menuBar);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	
	}
	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		
		Widget selectedItem = (Widget) ((e.item != null) ? e.item : e.getSource());
		
		if (selectedItem instanceof MenuItem) {
			MenuItem menuItem = (MenuItem) selectedItem;
			if(menuItem == exitMenuHeader) {
				display.dispose();
			}
			else if (menuItem == createCloudSpaceItem) {
				Rectangle r = shell.getClientArea();
				Label label = new Label(shell, SWT.NONE);
				label.setSize(200,50);
				label.setLocation(100,100);
				label.setText("sarayu is a doodle head");
				label.setEnabled(true);
				
				Label label1 = new Label(shell, SWT.NONE);
				label1.setSize(200,40);
				label1.setLocation(100,200);
				label1.setText("Shruthi is a doodle head");
				label1.setEnabled(true);
				System.out.println("Rectangle r " + r);
				
				Label shadow = new Label(shell, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);
				shadow.setBounds(50,80,100,50);
				shadow.setText("Hello world");
				
			}
			System.out.println("Menu Item selected " + menuItem);
		}
		else if (selectedItem instanceof Menu) {
			Menu menu = (Menu) selectedItem;
			System.out.println("Menu  selected " + menu);
		}
		
	}
	
	public static void main(String[] args) {
		 new CloudSpace();
	}

	
}
